import index from '@/views/index' 
import login from '@/views/login' 
import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

const originalPush = Router.prototype.push
const originalReplace = Router.prototype.replace
// push
Router.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
  return originalPush.call(this, location).catch((err) => err)
}
// replace
Router.prototype.replace = function push(location, onResolve, onReject) {
  if (onResolve || onReject) return originalReplace.call(this, location, onResolve, onReject)
  return originalReplace.call(this, location).catch((err) => err)
} 

export default new Router({
  routes: [
    {
      path: '/login',
      name: 'login',
      component: login
    },
    {
      path: '/',
      name: 'index',
      component: index, 
      redirect: '/dataAnalysis',
      children: [
        {
          path: "/dataAnalysis",
          name: "dataAnalysis",
          redirect: "/dataAnalysis/nationwide",
          component: () => import("@/views/dataAnalysis.vue"),
          children: [
            { 
              path: "/dataAnalysis/nationwide", 
              name: "nationwide", 
              component: () => import("@/views/dataAnalysis/nationwide.vue")
            },
            { 
              path: "/dataAnalysis/region", 
              name: "region", 
              component: () => import("@/views/dataAnalysis/region.vue")
            },
          ],
        },
        {
          path: "/dataCollection",
          name: "dataCollection",
          component: () => import("@/views/dataCollection.vue")
        },
        {
          path: "/Warning",
          name: "Warning",
          component: () => import("@/views/Warning.vue")
        }, 
        {
          path: "/monitorWarning",
          name: "monitorWarning",
          component: () => import("@/views/monitorWarning.vue")
        }, 
        {
          path: "/realInspection",
          name: "realInspection",
          component: () => import("@/views/realInspection.vue")
        }, 
        {
          path: "/roaming",
          name: "roaming",
          component: () => import("@/views/roaming.vue")
        }, 
      ]
    } 
  ]
})
